package com.aishua.andpaydemo.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;

/**
 * Created by aishua on 2018/5/16.
 */

public class BannerAdapter extends PagerAdapter {
    private static final String TAG = "BannerAdapter";
    private Context ctx;
    private List<View> mlist;

    public BannerAdapter(Context ctx, List<View> mlist) {

        this.ctx = ctx;
        this.mlist = mlist;

    }

    @Override
    public int getCount() {

        return mlist.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {

        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        container.addView(mlist.get(position));
//        mlist.get(position).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                Toast.makeText(ctx, "点击了" + position, Toast.LENGTH_SHORT).show();
//            }
//        });
        return mlist.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        container.removeView(mlist.get(position));
    }


}
